package com.inno.life.controller.controller;

import com.inno.life.common.entity.CommonReturnType;
import com.inno.life.controller.convert.MessagesDTOConverter;
import com.inno.life.controller.dto.MessagesDTO;
import com.inno.life.domain.entity.MessagesBO;
import com.inno.life.domain.service.LifeMessagesDomainService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/life/message")
public class LifeMessagesController {

    @Resource
    private LifeMessagesDomainService lifeMessagesDomainService;

    @PostMapping("/list")
    public CommonReturnType<List<MessagesDTO>> list(@RequestBody MessagesDTO messagesDTO){
        MessagesBO messagesBO = MessagesDTOConverter.INSTANCE.converDTOToBo(messagesDTO);
        List<MessagesBO> boList = this.lifeMessagesDomainService.queryList(messagesBO);

        return CommonReturnType.success(MessagesDTOConverter.INSTANCE.convertBOListToDTOList(boList));
    }

    @PostMapping("/read")
    public CommonReturnType<Void> read(@RequestBody MessagesDTO messagesDTO){
        MessagesBO messagesBO = MessagesDTOConverter.INSTANCE.converDTOToBo(messagesDTO);
        this.lifeMessagesDomainService.read(messagesBO);
        return CommonReturnType.success();
    }

    @PostMapping("/read/all")
    public CommonReturnType<Void> readAll(@RequestBody MessagesDTO messagesDTO){
        MessagesBO messagesBO = MessagesDTOConverter.INSTANCE.converDTOToBo(messagesDTO);
        this.lifeMessagesDomainService.readAll(messagesBO);
        return CommonReturnType.success();
    }
    @PostMapping("/unread/count")
    public CommonReturnType<MessagesDTO> unreadCount(@RequestBody MessagesDTO messagesDTO){
        MessagesBO messagesBO = MessagesDTOConverter.INSTANCE.converDTOToBo(messagesDTO);
        MessagesBO boResult = this.lifeMessagesDomainService.unreadCount(messagesBO);

        return CommonReturnType.success(MessagesDTOConverter.INSTANCE.converBOToDTO(boResult));
    }
}
